package servlet;

import pagination.PageBean;
import pojo.Brand;
import service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "SelectAllServlet",value = "/selectAll")
public class SelectAllServlet extends HttpServlet {
    //    创建业务层对象作为属性
    private BrandService brandService = new BrandService();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接受分页参数（当前是第？页，每一页大小为10个）
        String currentPage = request.getParameter("currentPage");
        int curPage = 1;//默认展示第1页
        if (currentPage !=null) {
            curPage = Integer.valueOf(currentPage);
        }
        int pageSize = 10; //几个分一页
//        1.调用BrandService 的selectAll() 方法进行业务逻辑处理，并接收返回的结果
            PageBean<Brand> pageBean = brandService.selectAllPage(curPage,pageSize);
//        2.返回的结果储存到request域对象中
        request.setAttribute("pageBean",pageBean);
//        3.跳转到brand.jsp  页面进行数据的展示
        request.getRequestDispatcher("/brand.jsp").forward(request,response);

    }
}
